package main

import (
	"fmt"
	"strings"
)

func main() {
	words := []string{"Hello", "Alaska", "Dad", "Peace"}
	fmt.Println(findWords(words))
}

var (
	first  = []byte{'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p'}
	second = []byte{'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l'}
	third  = []byte{'z', 'x', 'c', 'v', 'b', 'n', 'm'}
)

//#link: https://leetcode-cn.com/problems/keyboard-row/
func findWords(words []string) (ans []string) {
	firstMap := map[byte]bool{}
	secondMap := map[byte]bool{}
	thirdMap := map[byte]bool{}
	for _, i := range first {
		firstMap[i] = true
	}
	for _, i := range second {
		secondMap[i] = true
	}
	for _, i := range third {
		thirdMap[i] = true
	}

	a, b, c := 0, 0, 0
	for _, word := range words {
		for _, w := range []byte(strings.ToLower(word)) {
			if _, ok := firstMap[w]; ok {
				a = 1
			}
			if _, ok := secondMap[w]; ok {
				b = 1
			}
			if _, ok := thirdMap[w]; ok {
				c = 1
			}
		}
		if a+b+c == 1 {
			ans = append(ans, word)
		}
		a, b, c = 0, 0, 0
	}
	return ans
}
